package com.tengfei.ui_widget;

import android.os.Bundle;
import android.widget.CompoundButton;
import android.widget.Toast;
import android.widget.ToggleButton;

import androidx.appcompat.app.AppCompatActivity;

public class ToggleButtonActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_togglebutton);
        getSupportActionBar().setTitle("ToggleButton");
        ToggleButton tbDemo = findViewById(R.id.tb_demo);
        tbDemo.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
                Toast.makeText(ToggleButtonActivity.this,
                        compoundButton.getText(),
                        Toast.LENGTH_SHORT).show();
            }
        });
    }
}